package com.ricky;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * SpringBoot运行原理分析
 *
 * 注意  此种方式 默认需要内置tomcat或者内置jetty支持
 */
//开启SpringBoot自动注入配置  等价于原来的SpringBootApplication
@EnableAutoConfiguration
//开启RestController注解  含有ResponseBody 即非页面形式
@RestController
@PropertySource("extra.properties")
public class SpringBootApplication {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @GetMapping("/")
    public String home(HttpServletRequest request) {
        logger.info("HelloWorld 访问成功");
        return "Hello World!";
    }

    /**
     * 开启SpringBoot服务
     * @param args
     */
    public static void main(String[] args) {
        args=new String[2];
        System.out.println(args.toString());
        //等价于 new SpringApplication(SpringBootApplication.class).run(args);
        args[0]="--logging.level.root=info";
        args[1]="--logging.file=d:/work/log/chapter02_add.log";
        /*
            --logging.level.root=info --logging.file=d:/work/chapter02.log
        * */
        SpringApplication.run(SpringBootApplication.class,args);
    }
}